package com.yc.yyds.util;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.domain.AlipayTradePagePayModel;
import com.alipay.api.response.AlipayTradePagePayResponse;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.yc.yyds.Bean.Message;

public class AlipayTradePagePay {

    public static AlipayTradePagePayResponse alipay() throws AlipayApiException {
        String privateKey = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDVdGjMAbpunDeEWG7MGC4WcD5NlCJIJEaKHH+upndkUdzCTmc9jJUOYWcGlxzo5uCKHZ9E+DoA4UTEF+gsDo1qrH/w3ygnVotzQLiJ9q7SzfQgeZjbDERTn41DA+3utfUPbqFE+jG0ZizpVq0phnVgQVG2vHzOr2L0rKieoWMjMUweNDOo0nByO1x3rc+I78uD4ABh5nvLRhkSPTA2g4VbtXBilqKvPS4P8mfnlh1pnb4FwC0VpEds/MUf/KPg0R3g45y6S5Gq882/Qvic6CnH/rD6EvU6d2WKdQYMrvKDEwIg4UrL7rFrR1QLpg9Vc+ZbJOlR4q95+wN5L5y8MwbzAgMBAAECggEAbSR2qUmA8CnEYVFuZcE/X43I7ZX+6XBS+S+VQdIwXgVVoazBMUF+vbmkGkSOLbBPw49d7sAVuHl21eV7e3t9Z7wINzuDpomkCCxhr3mI7pUMbMaAGBDvpuqAKnIJ6PL0+Q0SPNjJLXrJIA6HwCHWRn9frtY14uDe8kiOd34B2O3eI6MdehehNA8/wN46UjBrb8/ky2TobW7A1bYetiQ8C0J7TZhO++MDxyB8+oi2CytTOd34OkDe+P/NYpLxe2RlWCWLERnU9r1IZeGo99KgoP3TIsqwKdSHVdTAe4oz4LJb+Md4vbIRD+pwgc8alq28GI0rofFz4ZDjr1IptuqQkQKBgQD99L67h50RNl3MAEMIcna8qdHR9TYWABKTDWaK0NGvioUodj4Z69n7PZXMZgG2QPoFB6iqeRqqg20xhKl7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eA7NSUJhb/CsawQ6SxF9yJrKGo0A8vhMS+18CuAkkagzNnMUNu6zty8DWFbEgcs4blVoXdeiqBa2C5taXIIHAv4romKfImgi10iKgB2aHYBanroKwbynxnwIDAQAB";
        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setServerUrl("https://openapi-sandbox.dl.alipaydev.com/gateway.do");
        alipayConfig.setAppId("2021000122662225");
        alipayConfig.setPrivateKey(privateKey);
        alipayConfig.setFormat("json");
        alipayConfig.setAlipayPublicKey(alipayPublicKey);
        alipayConfig.setCharset("UTF8");
        alipayConfig.setSignType("RSA2");
        AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig);
        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
        AlipayTradePagePayModel model = new AlipayTradePagePayModel();
        model.setOutTradeNo(Message.indentid);
        model.setTotalAmount(Message.money);
        model.setSubject("YYDS电影票");
        model.setProductCode("FAST_INSTANT_TRADE_PAY");

        request.setBizModel(model);
        request.setReturnUrl("http://localhost:8080/YYDSCINEMA_war_exploded/buyticks.html");
        AlipayTradePagePayResponse response = alipayClient.pageExecute(request);
        System.out.println(response.getBody());
        if (response.isSuccess()) {
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
        }
        return response;
    }
}